package cn.java78.jdbc;

import cn.myschool.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author oldliu
 * @since 1.0
 */
public class GundongSearch {
    public static void main(String[] args) {
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            con= DBUtil.getConnection();
            ps=con.prepareStatement("select * from s_student order by stuno desc",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            rs=ps.executeQuery();
            for(int i=1;i<=10&&rs.next();i++){
                System.out.println(i+":"+rs.getLong("stuno")+","+rs.getString("sname"));

            }
            rs.previous();//回退一条
            rs.previous();
            rs.previous();
            System.out.println("第七条：");
            System.out.println(rs.getLong("stuno")+","+rs.getString("sname"));

            System.out.println("直接去100");
            rs.absolute(100);
            for(int i=1;i<=10&&rs.next();i++){
                System.out.println(i+":"+rs.getLong("stuno")+","+rs.getString("sname"));

            }
            //boolean execute = ps.execute();

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rs,ps,con);
        }
    }
}
